﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace A5Site
{
    public partial class TimeRangePicker : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        
        protected void TimePicker1_TimeChanged(object sender, EventArgs e)
        {
            if (TimePickerEnd.SelectedTime.TimeOfDay.CompareTo(TimePickerStart.SelectedTime.TimeOfDay) <= 0)
            {
                DateTime tp2 = TimePickerEnd.SelectedTime;
                tp2 = tp2.AddMinutes(1);
                TimePickerEnd.SelectedTime = tp2;
                lbl_selectionError.Text = "Start Time must be before End Time";
                TimePicker2_TimeChanged(null, null);
            }
            else
            {
                lbl_selectionError.Text = "";
            }
            TimePickerEnd.LowerBoundTime = TimePickerStart.SelectedTime.AddMinutes(1);
        }

        protected void TimePicker2_TimeChanged(object sender, EventArgs e)
        {
            if (TimePickerEnd.SelectedTime.TimeOfDay.CompareTo(TimePickerStart.SelectedTime.TimeOfDay) <= 0)
            {
                DateTime tp1 = TimePickerStart.SelectedTime;
                tp1 = tp1.AddMinutes(-1);
                TimePickerStart.SelectedTime = tp1;
                lbl_selectionError.Text = "End Time must be after Start Time";
                TimePicker1_TimeChanged(null, null);
            }
            else
            {
                lbl_selectionError.Text = "";
            }
            TimePickerStart.UpperBoundTime = TimePickerEnd.SelectedTime.AddMinutes(-1);

        }

        public DateTime getStartTime()
        {
            return TimePickerStart.SelectedTime;
        }
        public DateTime getEndTime()
        {
            return TimePickerEnd.SelectedTime;
        }


    }
}